<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>在线投票系统</title>
<link type="image/x-icon" href="../images/yc.png" rel="shortcut icon"/>
<link type="text/css" rel="stylesheet" href="../css/style.css" />
<link type="text/css" rel="stylesheet" href="../blue/doubleDate.css" />
<script type="text/javascript">
var isIE = !!document.all;
function AddOption()
{
	var voteoptions = document.getElementById("voteoptions");
	var _p = document.createElement("p");
	var _input = document.createElement("input");
	_input.type = "text";
	_input.className = "input-text";
	_input.setAttribute("name", "options");
	_p.appendChild(_input);
	var _a = document.createElement("a");
	_a.className = "del";
	_a.setAttribute("href", "javascript:;");
	if(isIE) {
		_a.attachEvent("onclick", DelOption);
	} else {
		_a.addEventListener("click", DelOption, false);
	}
	_a.appendChild(document.createTextNode("删除"));
	_p.appendChild(_a);
	voteoptions.appendChild(_p);
}
function DelOption(e)
{
	if(!e) e = window.event;
	var a = e.srcElement || e.target;
	var obj = a.parentNode;
	obj.parentNode.removeChild(obj);
}
</script>
</head>
<body>


 
<div id="header" class="wrap">
	<img src="../images/logo.gif" />
</div>
<div id="navbar" class="wrap">
	<div class="profile">
		<span v-if="login">您好,{{userInfo.uname}}</span>
		<span v-else><a href="../login.html">登陆</a></span>
		<span class="modify"><a href="manage.html" target="_blank">管理页面</a></span>
		<span class="addnew"><a href="add.html" target="_blank">添加新投票</a></span>
		
	</div>
	<div class="search">
		<form method="post" action="Subject!search.action">
			<input type="text" name="keywords" class="input-text" value=""/>
			<input type="submit" name="submit" class="input-button" value="" />
		</form>
	</div>
</div>

<div id="voteManage" class="box">
	<h2>添加新投票</h2>
	<div class="content">
	<form onsubmit="return add()" id="myform">
			<dl>
				<dt>投票内容：</dt>
				<dd>
				   <input type="text" class="input-text" id="title"  value=""/>
				</dd>
				<dt>投票类型：</dt>
				<dd>
		  		   <input type="radio" name="type"  checked="checked" value="1" />单选
				   <input type="radio" name="type" value="2" />多选
				</dd>
				<dt>开始日期：</dt>
				<dd>
				   <input type="text" id="startDate" class="doubledate ipticon" readonly="readonly"/>
				   至  <input type="text" id="endDate" class="doubledate ipticon" readonly="readonly"/>
				</dd>

				<dt>投票选项：</dt>
				<dd id="voteoptions">
					<p><input type="text" class="input-text" name="options" /></p>
					<p><input type="text" class="input-text" name="options" /></p>
				</dd>
				
				
				<dt></dt>
				<dd class="button">
					<input type="image" src="../images/button_submit.gif" />
					<a href="javascript:;" onclick="AddOption()">增加选项</a>
					<a href="Subject!list.action">取消操作</a>
				</dd>
			</dl>
		</form>
	</div>
</div>
<div id="footer" class="wrap">
	憬荃 &copy; 版权所有
</div>

<script type="text/javascript" src="../js/jquery-1.12.4.js"></script>
<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
<script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript" src="../js/axios.js"></script>
<script type="text/javascript" src="../js/qs.js"></script>
<script type="text/javascript" src="../js/basic.js"></script>
<script type="text/javascript">

</script>
<script type="text/javascript">
$(function(){
	$('.doubledate').kuiDate({
		className:'doubledate',
		isDisabled: "0"  // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
	});
});

function add(){
	var title = $.trim($("#title").val());
	var type = $.trim($("#myform input[name='type']:checked").val());
	var sdate = $.trim($("#startDate").val());
	var edate = $.trim($("#endDate").val());
	var options = [];
	
	$("#voteoptions input").each(function(index, item){
		options.push(item.value);
	})
	
	var obj = {tname:title, type:type, sdate:sdate, edate:edate, uname:options.join(";") };
	$.post("../topic/add", obj, rt =>{
		if(rt.code == 200){
			$("#myform")[0].reset();
			alert("添加成功...");
			return;
		}
		alert("添加失败...");
	},"json");
	return false;
}
	
	
</script>
</body>
</html>

